<?php

/**
 * 发送邮件
 * @param $email
 * @param $title
 * @param $content
 * @return bool|string
 * @throws phpmailerException
 */
function sentEmail($email,$title,$content){
    //获取配置文件
    $option = C('EMAIL');
    //载入自动加载文件
    vendor('PHPMailer.PHPMailerAutoload');
    $mail = new \PHPMailer;

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host       = $option['host'];  // Specify main and backup SMTP servers
    $mail->SMTPAuth   = true;                               // Enable SMTP authentication
    $mail->Username   = $option['username'];                 // SMTP username
    $mail->Password   = $option['password'];                           // SMTP password
    $mail->SMTPSecure = $option['smtp'];                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port       = $option['port'];                                    // TCP port to connect to

    $mail->setFrom($option['setEmail'], $option['setEmailName']);
    $mail->addAddress($email);     // Add a recipient

    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->CharSet = $option['charset'];
    $mail->Subject = $title;
    $mail->Body    = $content;
    //如果发送成功返回true  否则返回错误信息
    return $mail->send() ? true : $mail->ErrorInfo;
}
